import java.util.Arrays;

public class Test02 {
    public static void merge(int A[], int m, int B[], int n) {
        int i = 0;
        int j = 0;
        int size = 0;
        int[] C = new int[m + n];
        while(i < m && j < n){
            if(B[j] <= A[i]){
                C[size++] = B[j++];
            }else{
                C[size++] = A[i++];
            }
        }
        if(i == m && j != n){
            while(j < n){
                C[size++] = B[j++];
            }
        }

        if(i != m && j == n){
            while(i < m){
                C[size++] = A[i++];
            }
        }

        for(int x = 0; x < C.length; x++){
            A[x] = C[x];
        }
    }

    public static void main(String[] args) {
        int[] A = new int[]{4,5,6,0,0,0};
        int[] B = new int[]{1,2,3};
        merge(A,3,B,3);
        System.out.println(Arrays.toString(A));
    }
}
